(function () {
  new Vue({
    el: '#changeContent',
    data() {
      return {
        groupLogs: [],
        publicLogsTypes: ['text', 'value', 'change', 'delete'],
        mode: hlUrlUtil.GetQueryString('mode'), //变更模式
        getContractIndex: JSON.parse(window.sessionStorage.getItem('CHANGE_CONTRACT_INDEX')),
        data: {},
        publicGroup: ['Y', 'N'],
        publicFlag: ['Y', 'N'],
        cutChangeFlowFlag: false,
      }
    },
    methods: {
      // 上一步/下一步
      previous() {
        window.changePage.pageIndex--
      },
      next() {
        window.changePage.pageIndex++
      },
      cutChangeFlow() {
        this.cutChangeFlowFlag = !this.cutChangeFlowFlag;
        if (this.cutChangeFlowFlag) {
          this.publicLogsTypes = ['change', 'delete']
          this.publicGroup = ['Y']
          this.publicFlag = ['Y']
        }
        if (!this.cutChangeFlowFlag) {
          this.publicLogsTypes = ['text', 'value', 'change', 'delete']
          this.publicGroup = ['Y', 'N', '']
          this.publicFlag = ['Y', 'N']
        }
      },
      // 保存
      save() {
        if (this.mode == 'edit') {
          hlhttp.put({
            url: 'contract_history',
            data: this.data,
            success: (res) => {
              hl.toast('编辑成功')
              this.clearStorage()
              hlUrlUtil.goTo('contractUpdateList')
            }
          })
        } else {
          hlhttp.post({
            url: 'contract_history',
            data: this.data,
            success: (res) => {
              hl.toast('保存成功')
              this.clearStorage()
              hlUrlUtil.goTo('contractUpdateList')
            }
          })
        }
      },
      // 提交审核
      submit() {
        hlhttp.put({
          url: 'contract_history/_submit',
          data: this.data,
          success: (res) => {
            hl.toast('提交审核成功')
            this.clearStorage()
            hlUrlUtil.goTo('contractUpdateList')
          }
        })
      },
      // 清缓存
      clearStorage() {
        var keyArr = [
          'CHANGE_CONTRACT_INDEX',
          'CHANGE_CONTRACT_GROUPLOPS',
          'CHANGE_CONTRACT_CONTRAST',
          'CHANGE_CONTRACT_002',
          'pageIndex',
          'CONTRACT_DETAIL'
        ]
        hlStorage.ssClearMultipleKey(keyArr)
      },

    },
    mounted() {
      this.groupLogs = JSON.parse(window.sessionStorage.getItem('CHANGE_CONTRACT_GROUPLOPS'))
      this.data = JSON.parse(window.sessionStorage.getItem('CHANGE_CONTRACT_CONTRAST'))
      this.data.agreement_flag = this.getContractIndex.agreement_flag
      this.data.agreement_attachment_names = this.getContractIndex.agreement_attachment_names || '#'
      this.data.agreement_attachment_urls = this.getContractIndex.agreement_attachment_urls || '#'
    },
  })
}())
